﻿using NUnit.Framework;
using Novice.Units.Tree;

namespace Novice.Units.Test
{
    [TestFixture]
    public class Test01
    {
        #region private data

        private readonly UnitMocks _units;
        private readonly IUnitAlgebra _algebra;

        #endregion

        public Test01()
        {
            _units = new UnitMocks();
            _algebra = new TreeUnitsAlgebra();

        }

        [Test]
        public void Convert()
        {
            var kg = _algebra.MakeValue(1.0, _units.Kilogramm);
            Assert.AreEqual(1000, kg.GetAs(_units.Gramm));
        }

        [Test]
        public void CheckEquivalent()
        {
            var l = _algebra.MakeValue(1.0, _units.BigCup);
            var tbsp = _algebra.MakeValue(1.0, _units.TableSpoon);
            
            Assert.IsTrue(l.IsEquivalentTo(tbsp));
            Assert.IsTrue(l.IsEquivalentTo(tbsp.Unit));
        }

        [Test]
        public void CheckNonequivalent()
        {
            var l = _algebra.MakeValue(1.0, _units.BigCup);
            var psc = _algebra.MakeValue(1.0, _units.Piece);

            Assert.IsFalse(l.IsEquivalentTo(psc));
            Assert.IsFalse(l.IsEquivalentTo(psc.Unit));
        }
    }
}
